package com.jinbei.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinbei.common.util.AuthorAnnotationUtil;
import com.jinbei.domain.Authority;
import com.jinbei.mapper.AuthorityMapper;
import com.jinbei.service.AuthorityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zflu
 * Created by lucky on 2018/7/9.
 */
@Service
public class AuthorityServiceImpl  implements AuthorityService {

    private final Logger logger = LoggerFactory.getLogger(AuthorityServiceImpl.class);

    @Autowired
    private AuthorityMapper authorityMapper;

    /**
     * @author zflu
     * @Description  权限新增
     * @date 2018-7-9 15:47:09
     * @param authority
     * @return int
     */
    @Override
    public int insertAuthority(Authority authority) throws Exception {
        return authorityMapper.insertAuthority(authority);
    }

    /**
     * @author zflu
     * @Description  权限修改
     * @date 2018-7-9 15:47:09
     * @param authority
     * @return int
     */
    @Override
    public int updateAuthority(Authority authority) throws Exception {
        return authorityMapper.updateAuthority(authority);
    }

    /**
     * @author zflu
     * @Description 根据权限id删除权限
     * @date 2018-7-9 15:47:09
     * @param id
     * @return int
     */
    @Override
    public int deleteAuthorityById(int id) throws Exception {
        return authorityMapper.deleteAuthorityById(id);
    }

    /**
     * @author zflu
     * @Description 根据权限id查询权限
     * @date 2018-7-9 15:47:09
     * @param id
     * @return com.jinbei.domain.Authority
     */
    @Override
    public Authority queryAuthorityById(int id) throws Exception {
        return authorityMapper.queryAuthorityById(id);
    }

    /**
     * @author zflu
     * @Description 日志记录分页列表
     * @date 2018/7/12 9:40
     * @param pageNum, pageSize
     * @return com.github.pagehelper.PageInfo
     */
    @Override
    public PageInfo queryAuthorityPage(int pageNum, int pageSize) throws Exception {
        PageHelper.startPage(pageNum,pageSize);
        List<Authority> authorities = authorityMapper.queryAuthorityPage();
        return new PageInfo(authorities);
    }

    @Override
    public Map<String, Object> queryAllAuthorUrl() throws Exception {
        return AuthorAnnotationUtil.getAuthor();
    }
}
